// 定义路由
import Vue from 'vue'
import VueRouter from 'vue-router';
Vue.use(VueRouter)

// 导入页面组件
import Home from '@/views/Home'
import Topic from '@/views/Topic'
import Category from '@/views/Category'
import Car from '@/views/Car'
import User from '@/views/User'
import Search from '@/views/Search'
import ProductDetail from '@/views/ProductDetail'


// 配置路由规则
const routes = [{
        path: '/',
        redirect: '/home',
    }, {
        path: '/home',
        component: Home,
        name: 'home',
        meta: {
            isshowtanbar: true // meta 字段为路由元信息,给当前路由添加一些标记信息
        },
        children: [{
            path: 'search', // 搜索页定义成二级路由
            component: Search,
            meta: {
                isshowtanbar: false
            },
        }]
    },
    {
        path: '/topic',
        component: Topic,
        name: 'topic',
        meta: {
            isshowtanbar: true
        },
    },
    {
        path: '/category',
        component: Category,
        name: 'category',
        meta: {
            isshowtanbar: true
        },
    },
    {
        path: '/car',
        component: Car,
        name: 'car',
        meta: {
            isshowtanbar: true
        },
    },
    {
        path: '/user',
        component: User,
        name: 'user',
        meta: {
            isshowtanbar: true
        },
    },
    {
        path: '/productdetail',
        component: ProductDetail,
        name: 'productdetail',
        meta: {
            isshowtanbar: false
        },
    },

]

// 创建路由实例对象
const router = new VueRouter({
    mode: 'history',
    routes
})

// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
//   return originalPush.call(this, location).catch(err => err)
// }


export default router